/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rnavizexperimentation;

import java.util.LinkedList;

/**
 *
 * @author Elias la Cour
 */
public class Model {

    private Structure structure = null;

    protected Structure findEdges(Structure structure) {
        this.structure = structure;
        return structure;
    }

    /**
     * returns a linkedlist of edges (knots) in a structure
     * @param st takes a Structure as parameter
     */
    public Structure tieKnots(Structure st) {
        LinkedList<Knot> knots = new LinkedList<Knot>();
        LinkedList<Knot> normalKnots = new LinkedList<Knot>();
        LinkedList<Knot> pseudoKnots = new LinkedList<Knot>();
        char[] dotSequence = st.getDotSequence();
        char[] baseSequence = st.getBaseSequence();
        int counter = 1; //tmp counter for storing position of a nucleotide,
        //should be handled by inputclass

        for (int e = 0; e < dotSequence.length; e++) {
            //for (char e : dotSequence) {
            counter++;
            if (dotSequence[e] == '(') {
                Base b = new Base(baseSequence[e], counter);
                normalKnots.add(new Knot(b));
            }
            if (dotSequence[e] == '[') {
                Base b = new Base(baseSequence[e], counter);
                Knot k = new Knot();
                k.setIsPseudo(true);
                pseudoKnots.add(k);
            }
            if (dotSequence[e] == ')') {
                Base b = new Base(baseSequence[e], counter);
                Knot k = normalKnots.pop();
                k.setB2(b);
                knots.add(k);
            }
            if (dotSequence[e] == ']') {
                Base b = new Base(baseSequence[e], counter);
                Knot k = pseudoKnots.pop();
                k.setB2(b);
                knots.add(k);
            }
        }
        st.setKnots(knots);
        return st;
    }

    public void drawLinearFeynman(Structure st) {
        
    }

    public void drawCircularFeynman(Structure st) {
    }

    public void drawSecondaryStructure(Structure st) {
    }

    /**
     * @param structure the structure to set
     */
    public void setStructure(Structure structure) {
        this.structure = structure;
    }
}
